import fs from 'fs-extra'
import path from 'path'

// 复制publish下的 lib 文件夹 到 dist 的 publish 文件夹中
// 源文件夹和目标文件夹
const copyArr = ['lib']
copyArr.forEach((item) => {
  const sourceDir = path.resolve('public', item)
  const targetDir = path.resolve('dist', 'public/' + item)
  // 复制文件夹及其内容
  fs.copySync(sourceDir, targetDir)
})

// 获取本地时间的各个部分
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0') // 月份是从 0 开始的
const day = String(now.getDate()).padStart(2, '0')
const hours = String(now.getHours()).padStart(2, '0')
const minutes = String(now.getMinutes()).padStart(2, '0')
const seconds = String(now.getSeconds()).padStart(2, '0')

// 格式化为 YYYY-MM-DD HH:MM:SS
const dateString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`

// 获取当前目录
const scriptContent = `
console.log('名称: 亦庄4.0 web')
console.log('版本: versions--1.0.0')
console.log('打包日期: ${dateString}');
`
const outputPath = path.resolve('dist/public/lib', 'versions.js') // 输出路径

fs.writeFileSync(outputPath, scriptContent)

const name = `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`
const filePath = path.resolve('dist', `version_${name}.txt`)
const content = `打包日期: ${dateString}`

fs.writeFileSync(filePath, content, 'utf8')
